import BaseUtil from '@/BaseUtil';
import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import EffectUtil from '@/EffectUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 战马冲锋
 **/
export default class QS_RiderAssault extends AbilityBase {
    static instance: QS_RiderAssault;
    buffType: AppBuffType = {
        id: 'buff_QS_RiderAssault',
        art: this.art,
        name: this.abilityName,
        ubertip: '增加移动速度，并hitFly前方的敌人',
        dur: 4,
        attribute: {
            move_speed_p: 0.6,
        },
        onDestroy: this.onBuffDestory.bind(this),
        interval: 0.05,
        onInterval: this.onBuffInterval.bind(this),
    };
    onBuffInterval(buff: Buff) {
        let source = buff.getCaster();
        let es = SelectUtil.getEnemyUnitsInRange(source, 175);
        let lv = this.getAbilityLevel(source);
        let dmg = 40 * lv + UnitCommon.取攻击(source) * (0.25 + 0.35 * lv) + UnitCommon.取法强(source) * (0.25 + 0.35 * lv);
        for (let e of es) {
            MovementCommon.hitFly({
                target: e,
                caster: source,
                distance: 250,
                maxHeight: 150,
                speed: 800,
                angle: MathUtil.angleBetweenCoords(GetUnitX(source), GetUnitY(source), GetUnitX(e), GetUnitY(e)),
            });
            DamageSystemInstance.applyLightDamage(e, source, dmg, this.id);
            DestroyEffect(AddSpecialEffectTarget('Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl', e, 'origin'));
        }
    }
    onBuffDestory(buff: Buff) {
        SetUnitPathing(buff.getCaster(), true);
        DzUnbindEffect(buff.effect);
        EffectUtil.destroyEffectNoDeathAnim(buff.effect);
    }
    constructor(id: string) {
        super(id);
        QS_RiderAssault.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        PlaySound('Units\\Human\\KnightNoRider\\KnightNoRiderYes2.wav');
        let buff = BuffCommon.addBuff({ target: source, caster: source, buffTypeId: this.buffType.id, ablityId: this.id });
        buff.effect = AddSpecialEffectTarget('units\\human\\KnightNoRider\\KnightNoRider.mdx', source, 'origin');
        DzPlayEffectAnimation(buff.effect, 'walk', '');
        SetUnitPathing(source, false);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
